<?php		
	//session_start();
	if(isset($_COOKIE['email'])){
		$email = $_COOKIE['email'];
	}
	if(isset($_COOKIE['senha'])){
		$senha = $_COOKIE['senha'];
	}
	if(!(empty($email)) and !(empty($senha))){
		$sql = "SELECT * FROM pessoa WHERE email ='$email'";
		$rs = mysql_query($sql,$con);
		if(mysql_num_rows($rs)==1){
			if($senha != mysql_result($rs,0,"senha")){
				//senha errada!!
				setcookie("email","", time()-3600);
				setcookie("senha","", time()-3600);
				session_destroy();
				
			}
			else{
				//cookie valido
				session_start();
				setcookie("email",$email, time()+60*60*24);
				setcookie("senha",$senha, time()+60*60*24);
				$_SESSION['email'] = $email;
				$_SESSION['senha'] = $senha;
				$_SESSION['cd_pessoa'] = mysql_result($rs,0,'cd_pessoa');
				$_SESSION['tipo_usuario'] = mysql_result($rs,0,'tipo_usuario');
				
			}
		}
		else{
			//user não encontrado
			setcookie("email","", time()-3600);
			setcookie("senha","", time()-3600);
			session_destroy();
			//setcookie("senha2");
			
		}
	}
	else{
		if(!(empty($email))) {
			setcookie("email","", time()-3600);
			
		}
		if(!(empty($senha))){
			setcookie("senha","", time()-3600);
		}
		session_destroy();
		
	}
		
		
		
		
?>